package com.admin.controllerv1;

import com.admin.service.AdChannelService;
import com.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Api(value = "频道管理",tags = "channel",description = "频道管理Apl")
@RequestMapping("/admin/api/v1/channel")
@RestController
@CrossOrigin
public class AdChannelController implements AdChannelControllerApi {

    /**
     * 根据姓名去查询对应的channal中的数据
     * @param channelDto
     * @return
     */
    @Autowired
    private AdChannelService channelService;


    @PostMapping("list")
    @Override
    @ApiOperation(value = "频道查询",notes = "分页")
    @ApiImplicitParam(name = "channelDto",type = "ChannelDto",value = "分页参数")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return channelService.findByNameAndPage(channelDto);
    }

    /**
     * del:根据主键id  删除操作
     * @param id
     * @return
     */
    @GetMapping("del/{id}")
    @Override
    @ApiOperation(value = "频道删除",notes = "删除")
    @ApiImplicitParam(name = "id",type = "Integer",value = "删除参数")
    public ResponseResult del(@PathVariable Integer id) {
        return channelService.del(id);
    }

    /**
     * save :添加
     * @param adChannel
     * @return
     */
    @PostMapping("save")
    @Override
    @ApiOperation(value = "频道添加",notes = "添加")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "添加参数")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        return channelService.saveAdChannel(adChannel);
    }

    /**
     * update:修改
     * @param adChannel
     * @return
     */
    @PostMapping("update")
    @Override
    @ApiOperation(value = "频道修改",notes = "修改")
//    多个参数 ApiImplicitParams
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "修改参数")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return channelService.update(adChannel);
    }
}
